﻿using System;
using System.Linq;
using Dorm.Maps;
using Dorm.QueryObject;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Dorm.Tests
{
    [TestClass]
    public class Script_Tests
    {
        [TestMethod]
        public void Can_Generate_Database_Scripts()
        {
            string script = new Database().ScriptAll();
            Console.WriteLine(script);
        }

        [TestMethod]
        public void Can_Run_All_Queries()
        {
            var mapTypes = MapLocator.GetAllEntityMapTypes().Where(t => t.BaseType.Name.StartsWith("EntityMap"));

            using (var db = new Database())
            {
                foreach (var mapType in mapTypes)
                {
                    Type entityType = mapType.BaseType.GetGenericArguments()[0];
                    Type generic = typeof (Query<>).MakeGenericType(entityType);
                    dynamic query = Activator.CreateInstance(generic);
                    db.List(query.Top(0));
                }
            }
        }
    }
}
